<?php

/**
 * @author luhua
 */
class CategoryModel extends Model {

    protected $_validate = array(
        array('category_name', 'require', '{%v_category_name_is_required}'),
        array('identify', 'checkIdentify', '{%v_identify_is_required}',0,'callback'),
        array('parent_id', 'require', '{%v_parent_is_required}'),
        array('position', 'require', '{%v_position_is_required}')
    );

   /**
     * 標識檢測
     * @param string $identify
     * @return boolen 
     */
    public function checkIdentify($identify){
        $language = $_POST['language'];
        $pk = $this->getPk();
        $id = $_POST[$pk];
        if($language) {
            if(preg_match("/^[a-zA-Z0-9_]+$/",$identify)){
                $row = $this->where("language = '$language' and identify = '$identify'")->find();
                if($id) {
                    debug($id);
                   if($row && $row[$pk] != $id) return false; 
                } else {
 
                   if($row) return false; 
                }
                return true;
            }
            return false;
        }
        return true;
    }

}

?>
